<?php
namespace app\controllers\feed;

use fate\db\Db;
use fate\http\Request;
use app\libs\Rssbaidu;

class IndexController {
    private $baseUrl = '';
    private $subFix = '';
    private $db = null;

    public function __construct() {
        $this->baseUrl = Request::getInstance()->getHostInfo();
        $this->db = Db::instance('main');
    }

    // 默认订阅技术
    public function run() {
        // 拿到文章
        $dataList = $this->db->createQuery()
            ->select('id,tags,title,brief,post_time')
            ->from('t_post')->orderBy('id desc')->limit(50)->getAll();

        $rss = new Rssbaidu();

        for($i = 0, $len=count($dataList); $i < $len; $i++) {
            $rss->addItem(
                $dataList[$i]['title'],
                $this->baseUrl . '/posts?id=' . $dataList[$i]['id'] . $this->subFix,
                date('Y-m-d H:i:s', $dataList[$i]['post_time']));
        }

        $rss->show();
    }
}
